<?php

namespace RoleUser\Service;
use RoleUser\Mapper\RoleInterface;
use RoleUser\Mapper\RoleMapper;

use User\Service\User as User;

class RoleUser extends User
{
    CONST ROLE_USER = 2;
    protected $roleMapper;

    public function setRoleMapper(RoleInterface $roleMapper)
    {
        $this->roleMapper = $roleMapper;
        return $this;
    }

    public function getRoleMapper()
    {
        if (null === $this->roleMapper) {
            $this->roleMapper = $this->getServiceManager()->get('user_role_mapper');
        }
        return $this->roleMapper;

    }

    public function register(array $data)
    {
        $user = parent::register($data);
        if($user !== false) 
        {
            $userRole = array(
                'user_id' => $user->getUserId(),
                'role_id' => self::ROLE_USER,//$user->getRoles()[0]->getRoleId() , //'user'
            );
            $this->getRoleMapper()->insert($userRole);
        }
        return $user;
    }

} 